package com.blovesoft.tokenup.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.blovesoft.tokenup.R;
import com.llkj.common.base.BaseActivity;
import com.llkj.common.di.component.AppComponent;
import com.llkj.common.util.GlideApp;
import com.llkj.common.widget.titlebar.TitleBar;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/5/28
 * desc  : 个人信息
 */
public class UserInfoActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.view_click_head)
    View viewClickHead;
    @BindView(R.id.iv_head)
    ImageView ivHead;
    @BindView(R.id.tv_username)
    TextView tvUsername;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_userinfo;
    }

    @Override
    public boolean useEventBus() {
        return false;
    }

    @Override
    public void initView() {
        GlideApp.with(this)
                .load(R.drawable.ic_launcher_background)
                .circleCrop()
                .into(ivHead);
    }

    @Override
    public void initData() {

    }

    @Override
    public void getBundleExtras(Bundle extras) {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @OnClick({R.id.view_click_head, R.id.view_click_name})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.view_click_head:
                PictureSelector.create(this)
                        .openGallery(PictureMimeType.ofImage())
                        .isCamera(true)
                        .theme(R.style.picture_default_style)
                        .selectionMode(PictureConfig.SINGLE)
                        .previewImage(true)
                        .previewEggs(true)
                        .synOrAsy(false)
                        .enableCrop(true)
                        .compress(true)
                        .minimumCompressSize(100)
                        .glideOverride(160, 160)
                        .forResult(PictureConfig.CHOOSE_REQUEST);
                break;
            case R.id.view_click_name:
                startActivity(UpdateNickNameActivity.class);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    List<LocalMedia> localMedias = PictureSelector.obtainMultipleResult(data);
                    if (localMedias != null && localMedias.size() > 0) {
                        LocalMedia localMedia = localMedias.get(0);
                        String path = !StringUtils.isEmpty(localMedia.getCompressPath()) ? localMedia.getCompressPath() : localMedia.getPath();
                        GlideApp.with(this)
                                .load(path)
                                .circleCrop()
                                .into(ivHead);
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
